package com.hoas.quicksdk.api;

import com.hoas.quicksdk.api.sms.SmsRsp;

import java.io.Serializable;

public class ApiResult<T> implements Serializable {

    private boolean success;

    /**
     * code,200成功，其他为失败, 也可以用ifSuccess方法快速判断
     */
    private Integer code;

    /**
     * message,code对应到描述，如果code为非200则为错误提示，可以直接提示给用户
     */
    private String message;

    private T data;

    public ApiResult(boolean success, Integer code, String message) {
        this.success = success;
        this.code = code;
        this.message = message;
    }

    public static ApiResult paramError(String message) {
        return new ApiResult(false, 401, message);
    }

    public static ApiResult error(String message) {
        return new ApiResult(false, 500, message);
    }

    public static <T> ApiResult<T> businessError(String message, T data) {
        ApiResult result = new ApiResult(false, 501, message);
        result.data = data;
        return result;
    }

    public static <T> ApiResult<T> success(String message, T data) {
        ApiResult result = new ApiResult(true, 0, message);
        result.data = data;
        return result;
    }

    public static <T> ApiResult<T> success(String message) {
        ApiResult result = new ApiResult(true, 0, message);
        return result;
    }

}
